package com.ssm.gbq.service.impl;

import com.ssm.gbq.dao.DoctorDao;
import com.ssm.gbq.model.Doctor;
import com.ssm.gbq.service.DoctorService;
import gbq.ssm.utils.BusinessException;
import gbq.ssm.utils.PageBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DoctorServiceImpl implements DoctorService {

    @Autowired
    private DoctorDao doctorDao;

    public PageBounds<Doctor> openDoctorTable(String doctorName,String createTimeMax,String createTimeMin, int currentPage, int pageSize) throws Exception {
        try {
            return doctorDao.openDoctorTable( doctorName, createTimeMax, createTimeMin, currentPage, pageSize);
        } catch (Exception e) {
            throw new BusinessException("获取医生列表失败！", e.getMessage());
        }
    }

    public List<Doctor> selectAllDoctor() throws BusinessException {
        try {
            return doctorDao.selectAllDoctor();
        } catch (Exception e) {
            throw new BusinessException("查询失败！", e.getMessage());

        }
    }

    public void deleteDoctorByIds(List<Integer> ids) throws BusinessException {
        try {
            doctorDao.deleteDoctorByIds(ids);
        } catch (Exception e) {
            throw new BusinessException("删除失败！",e.getMessage());
        }
    }
   public int deleteDoctorById(Integer id){

           return doctorDao.deleteDoctorById(id);
   }

    public int addDoctor(Doctor doctor) throws BusinessException{
        try {
            return doctorDao.addDoctor(doctor);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 1;
    }

    public int updateDoctor(Doctor doctor) {
            return doctorDao.updateDoctor(doctor);
    }

    public Doctor findById(Integer id) {
        return doctorDao.findById(id);
    }
}
